package tiny.soft.com.common.resolver;

import org.springframework.core.MethodParameter;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;
import tiny.soft.com.common.annotation.InjectUser;

@Component
public class InjectUserResolver implements HandlerMethodArgumentResolver {
    @Override
    public boolean supportsParameter(MethodParameter methodParameter) {
        return methodParameter.getParameterType().isAssignableFrom(User.class) && methodParameter.hasParameterAnnotation(InjectUser.class);
    }

    @Override
    public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer modelAndViewContainer, NativeWebRequest nativeWebRequest, WebDataBinderFactory webDataBinderFactory) throws Exception {

        //UserAccountVo vo = (UserAccountVo) nativeWebRequest.getAttribute("ta3.userinfo", RequestAttributes.SCOPE_SESSION);
       /* if(null==null){
            //此处无须打印堆栈，错误码已经明确说明错误位置和类型，而且错误也是很正常的错误
            throw new BusinessException("METHOD-RESOLVER-NO-SESSION-USER", "您尚未登录或登录已超时，请登录后再操作！");
        }*/
        return null;
    }

}
